package com.pda.xinma.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.pda.xinma.R;
import com.pda.xinma.bean.WaitOutStockListBean;
import com.wangshen.base.ui.mvp.base.adapter.BaseAdapter;
import com.wangshen.base.util.ToastUtils;

import java.util.List;

public class HandOutStockAdapter extends BaseAdapter<WaitOutStockListBean> {
    OnSelectClick onSelectClick;
    private double toal;
    public HandOutStockAdapter(int layoutResId, @Nullable List<WaitOutStockListBean> data,OnSelectClick onSelectClick) {
        super(layoutResId, data);
        this.onSelectClick=onSelectClick;
    }

    public double getToal() {
        return toal;
    }

    public void setToal(double toal) {
        this.toal = toal;
    }

    @Override
    protected void convert(BaseViewHolder helper, WaitOutStockListBean item) {
        super.convert(helper, item);
        ImageView checkBox=helper.getView(R.id.cb_select);
        if (item.isSelect()){
            checkBox.setImageResource(R.mipmap.item_cb_hege_true);
        }else {
            checkBox.setImageResource(R.mipmap.item_cb_hege_false);
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onSelectClick != null){
                    if (!item.isSelect()){
                        if ((getIs()) > toal ){
                            ToastUtils.showToast(getContext(),"重量已经超过应出库重量！");
                            return;
                        }
                    }
                }
                item.setSelect(!item.isSelect());
                notifyDataSetChanged();
                if (onSelectClick != null){
                    onSelectClick.onClick();
                }
            }
        });
        helper.setText(R.id.tv_productModelAndBatch,item.getProductModelAndBatch());
        helper.setText(R.id.tv_container,"桶码编号: "+item.getContainer());
        helper.setText(R.id.tv_produceDate,"生产日期: "+item.getProduceDate());
        helper.setText(R.id.tv_indexNo,"桶号:"+item.getIndexNo()+"");
        helper.setText(R.id.tv_weight,"重量:"+item.getWeight()+item.getUnit());
        helper.setText(R.id.tv_apparentDensity,"松比: "+item.getApparentDensity());
        helper.setText(R.id.tv_liquidity,"流动性: "+item.getLiquidity());
    }
    public double getIs(){
        double num=0;
        for (WaitOutStockListBean item: getData()){
            if (item.isSelect()){
                num= num+Double.parseDouble(item.getWeight());
            }
        }
        return num;
    }
    public interface OnSelectClick{
       void onClick();
    }
}
